package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.GpRemark;
import com.stylefeng.guns.modular.system.service.IGpRemarkService;
import com.stylefeng.guns.modular.system.task.GpRemarkImportTask;
import com.stylefeng.guns.modular.system.warpper.GpRemarkWarpper;

/**
 * 股票池点评控制器
 *
 * @author fengshuonan
 * @Date 2018-07-31 11:27:20
 */
@Controller
@RequestMapping("/gpRemark")
public class GpRemarkController extends BaseController {

    private String PREFIX = "/system/gpRemark/";

    @Autowired
    private IGpRemarkService gpRemarkService;
    
    @Autowired
    private GpRemarkImportTask gpRemarkImportTask;

    /**
     * 跳转到股票池点评首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "gpRemark.html";
    }

    /**
     * 跳转到添加股票池点评
     */
    @RequestMapping("/gpRemark_add")
    public String gpRemarkAdd() {
        return PREFIX + "gpRemark_add.html";
    }

    /**
     * 跳转到修改股票池点评
     */
    @RequestMapping("/gpRemark_update/{gpRemarkId}")
    public String gpRemarkUpdate(@PathVariable Integer gpRemarkId, Model model) {
        GpRemark gpRemark = gpRemarkService.selectById(gpRemarkId);
        model.addAttribute("item",gpRemark);
        LogObjectHolder.me().set(gpRemark);
        return PREFIX + "gpRemark_edit.html";
    }

    /**
     * 获取股票池点评列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date) {
    	Page<GpRemark> page = new PageFactory<GpRemark>().defaultPage();
    	List<Map<String, Object>> gdhs = gpRemarkService.selectMapsByDm(page,date);
    	page.setRecords((List<GpRemark>) new GpRemarkWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增股票池点评
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(GpRemark gpRemark) {
        gpRemarkService.insert(gpRemark);
        return SUCCESS_TIP;
    }

    /**
     * 删除股票池点评
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer gpRemarkId) {
        gpRemarkService.deleteById(gpRemarkId);
        return SUCCESS_TIP;
    }

    /**
     * 修改股票池点评
     */
    @RequestMapping(value = "/updateRemark")
    @ResponseBody
    public Object updateRemark() {
    	gpRemarkImportTask.execute(true);
        return SUCCESS_TIP;
    }
    
    /**
     * 修改股票池点评
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(GpRemark gpRemark) {
        gpRemarkService.updateById(gpRemark);
        return SUCCESS_TIP;
    }

    /**
     * 股票池点评详情
     */
    @RequestMapping(value = "/detail/{gpRemarkId}")
    @ResponseBody
    public Object detail(@PathVariable("gpRemarkId") Integer gpRemarkId) {
        return gpRemarkService.selectById(gpRemarkId);
    }
}
